<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }
        body {
            background-color: #f5f7fa;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            padding: 20px;
        }
        .login-container {
            width: 100%;
            max-width: 400px;
            padding: 30px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
        }
        .form-group {
            margin-bottom: 18px;
        }
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #34495e;
            font-size: 14px;
        }
        input {
            width: 100%;
            padding: 12px;
            border: 1px solid #dcdfe6;
            border-radius: 4px;
            font-size: 15px;
        }
        input:focus {
            border-color: #3498db;
            outline: none;
        }
        .login-btn {
            width: 100%;
            padding: 12px;
            background-color: #3498db;
            color: white;
            border: none;
            border-radius: 4px;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            transition: background-color 0.2s;
        }
        .login-btn:hover {
            background-color: #2980b9;
        }
        .login-btn:disabled {
            background-color: #bdc3c7;
            cursor: not-allowed;
        }
        .message {
            margin-top: 18px;
            padding: 14px;
            border-radius: 4px;
            text-align: center;
            font-size: 14px;
            font-weight: 500;
        }
        .success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        .error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
    </style>
</head>
<body>
    <div id="app" class="login-container">
        <h2 style="text-align: center; margin-bottom: 25px; color: #2c3e50;">登录</h2>
        
        <div class="form-group">
            <label for="username">用户名</label>
            <input 
                type="text" 
                id="username" 
                v-model="username" 
                placeholder="请输入用户名"
                @keyup.enter="login">
        </div>
        
        <div class="form-group">
            <label for="password">密码</label>
            <input 
                type="password" 
                id="password" 
                v-model="password" 
                placeholder="请输入密码"
                @keyup.enter="login">
        </div>
        
        <button class="login-btn" @click="login" :disabled="isLoading">
            <span v-if="!isLoading">登录</span>
            <span v-else>登录中...</span>
        </button>
        
        <div v-if="message" class="message" :class="{ success: isSuccess, error: !isSuccess }">
            {{ message }}
        </div>
    </div>

    <script>
        const { createApp } = Vue;
        
        createApp({
            data() {
                return {
                    username: '',
                    password: '',
                    message: '',
                    isSuccess: false,
                    isLoading: false
                }
            },
            methods: {
                async login() {
                    this.message = '';
                    
                    if (!this.username.trim() || !this.password.trim()) {
                        this.message = '用户名和密码不能为空';
                        this.isSuccess = false;
                        return;
                    }
                    
                    this.isLoading = true;
                    
                    try {
                        const response = await axios.post('http://139.196.141.180/login', {
                            username: this.username,
                            password: this.password
                        });
                        
                        if (response.data.code === 0) {
                            this.message = response.data.message;
                            this.isSuccess = true;
                        } else {
                            this.message = response.data.message || '登录失败，请重试';
                            this.isSuccess = false;
                        }
                        
                    } catch (error) {
                        if (error.response) {
                            switch (error.response.status) {
                                case 400:
                                    this.message = error.response.data?.message || '请求参数不完整';
                                    break;
                                case 401:
                                    this.message = error.response.data?.message || '用户名或密码错误';
                                    break;
                                default:
                                    this.message = '服务器错误';
                            }
                        } else {
                            this.message = '网络连接错误';
                        }
                        this.isSuccess = false;
                    } finally {
                        this.isLoading = false;
                    }
                }
            }
        }).mount('#app');
    </script>
</body>
</html>
